#include <iostream>
#include <thread>
#include <set>
#include "../src/private/CanReader.h"
#include "../src/private/CanSender.h"

using std::make_unique;

int main() {
    const auto reader1 = make_unique<canpp::CanReader>("can0", "reader1", std::set<uint16_t>{0x200});
    std::this_thread::sleep_for(std::chrono::seconds(1));
    reader1->registerCallback(std::move([](const can_frame &frame) { std::cout << frame.can_id << "\n"; }));
    auto reader2 = make_unique<canpp::CanReader>("can1", "reader2", std::set<uint16_t>{0x200});
    std::this_thread::sleep_for(std::chrono::seconds(3));

    const auto sender1 = make_unique<canpp::CanSender>("can0", "sender1");
    can_frame frame = {0x130, {8}};
    std::array<uint8_t, 8> array{1, 2, 3, 4, 5, 6, 7, 8};
    std::ranges::move(array, frame.data);
    sender1->canSend(can_frame(frame));
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    sender1->canSend(can_frame(frame));
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    sender1->canSend(can_frame(frame));
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    sender1->canSend(can_frame(frame));
    std::this_thread::sleep_for(std::chrono::seconds(3));

    return EXIT_SUCCESS;
}
